package com.example.magicapi.controller;


//import com.github.sarxos.webcam.Webcam;
//import com.github.sarxos.webcam.WebcamResolution;
//import com.github.sarxos.webcam.WebcamUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

//import javax.annotation.Resource;
//import java.io.File;
//import java.text.SimpleDateFormat;
//import java.util.Date;
import java.util.Map;

/**
 * The type Dome controller.
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/api")
public class DomeController {

    private final Logger logger = LoggerFactory.getLogger(DomeController.class);

//    @Resource
//    private RedisTemplate<String, Object> redisTemplate;

//    @Value("${record.path}")
//    private String downloadPath;

    /**
     * Test 2 string.
     *
     * @param param the param
     * @return the STRING
     */
    @PostMapping("/test2")
    public String test2(@RequestBody Map<String, Object> param) {

        return param + "成功！";
    }

//    @GetMapping("/redis")
//    public String redis(String key, String value) {
//        logger.debug("key/value=" + key + "/" + value);
//        redisTemplate.opsForValue().set(key, value);
//        return (String) redisTemplate.opsForValue().get(key);
//    }

    /**
     * Test 1 string.
     *
     * @param param the param
     * @return the string
     */
    @GetMapping(value = "/test1", produces = "application/json;charset=utf-8")
    public String test1(String param) {

        return param + "成功！";
    }

//    @GetMapping(value = "/tp", produces = "application/json;charset=utf-8")
//    public String takePictures(String[] args) {
//        return takePictures();
//    }
//
//    public String takePictures() {
//        Webcam webcam = Webcam.getDefault();
//        if (webcam == null) {
//            return "没有找到摄像设备！";
//        }
//        String filePath = downloadPath + "/picture/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//        File path = new File(filePath);
//        if (!path.exists()) {//如果文件不存在，则创建该目录
//            boolean is = path.mkdirs();
//            if (is) {
//                logger.debug("创建文件夹");
//            }
//        }
//        String time = new SimpleDateFormat("yyyMMdd_HHmmss").format(new Date());
//        File file = new File(filePath + "/" + time + ".jpg");
//        webcam.setViewSize(WebcamResolution.VGA.getSize());
//        WebcamUtils.capture(webcam, file);
//        webcam.close();
//        return "拍照成功！";
//    }
}
